<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="layui/css/layui.css" rel="stylesheet">
    <script src="layui/layui.js"></script>
</head>
<body>

<form id="addUserDemo" lay-filter="addUserDemo"
      class="layui-form layui-form-pane"
      style="margin: 30px auto; display: inline-block;" >
    <div class="layui-form-item" style="text-align: center;">
        <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 200px">交易所名称</label>
        <div class="layui-input-inline">
            <select name="exchangeName" id="exchangeName">
                <option value="1">上交所</option>
                <option value="2">深交所</option>
                </select>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 200px">交易品种</label>
        <div class="layui-input-inline">
            <select name="exchangeType" id="exchangeType">
                <option value="1">股票</option>
                <option value="2">债券</option>
                </select>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 200px">印花税</label>
        <div class="layui-input-inline">
            <input type="text" lay-verify="required"
                   autocomplete="off" placeholder="印花税" class="layui-input" name="stampDuty">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 200px">过户费</label>
        <div class="layui-input-inline">
            <input type="text" lay-verify="required"
                   autocomplete="off" placeholder="过户费" class="layui-input" name="transferFee">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 200px">征管费</label>
        <div class="layui-input-inline">
            <input type="text" lay-verify="required"
                   autocomplete="off" placeholder="征管费" class="layui-input" name="collectionFee">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <label class="layui-form-label layui-bg-gray" style="width: 140px; margin-left: 200px">经手费</label>
        <div class="layui-input-inline">
            <input type="text" lay-verify="required"
                   autocomplete="off" placeholder="经手费" class="layui-input" name="handlingFee">
        </div>
    </div>

    <div class="layui-form-item" style="position: absolute;left: 20%; bottom: 20px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="addUser"><i class="layui-icon">&#x1005;</i>添加</button>
                <button type="reset" class="layui-btn layui-btn-primary"> <i class="layui-icon">&#x1006;</i>取消</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    layui.use('form',function (){
        var form = layui.form;
        var $ = layui.jquery;

        form.on('submit(addUser)',function(obj){
            console.log(obj.field);
            $.ajax({
                url:"insertExchange",
                type:"get",
                data:obj.field,
                dataType:"text",
                contentType:"application/x-www-form-urlencoded",//内容类型  form 表单的
                success:function(msg){
                    if(msg=="ok"){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        alert("增加成功！")
                    }else if(msg=="no"){
                        alert("费率已存在！")
                    }
                }
            });
            return false;//阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>
</body>
</html>
